﻿@using Magicodes.WeiChat.Data.Models.Site;
@model Site_ResourceType
@{
    ViewBag.Title = "";
    Layout = "~/Views/Shared/_LightLayout.cshtml";
}

<div class="row">
    <div class="col-lg-12">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                @using (Html.BeginRouteForm(routeName: "UploadFilesRoute", routeValues: new { Id = Request.RequestContext.RouteData.Values["Id"] }, method: FormMethod.Post, htmlAttributes: new { @class = "dropzone", id = "my-awesome-dropzone", enctype = "multipart/form-data" }))
                {
                    @Html.AntiForgeryToken()
                    switch (Model.ResourceType)
                    {
                        case SiteResourceTypes.Gallery:
                            break;
                        case SiteResourceTypes.Voice:
                            break;
                        case SiteResourceTypes.Video:
                            <div class="form-group">
                                <label class="col-sm-2 control-label">资源描述：</label>
                                <div class="col-sm-10">
                                    <textarea placeholder="请输入资源描述" name="description" class="form-control"></textarea>
                                </div>
                            </div>
                            break;
                        //case SiteResourceTypes.Thumb:
                        //    break;
                        default:
                            break;
                    }
                    <div class="dropzone-previews"></div>
                }
                @*<form id="my-awesome-dropzone" class="dropzone" action="@Url.Action("Upload",new { id=Request.QueryString["Id"] })" method="post" enctype="multipart/form-data">

                    </form>*@
            </div>
        </div>
    </div>
</div>
@section Styles {
    @Styles.Render("~/Content/plugins/dropzone/dropZoneStyles")
}

@section Scripts {
    @Scripts.Render("~/plugins/dropZone")

    <script type="text/javascript">

        $(document).ready(function () {
            Dropzone.options.myAwesomeDropzone = {
                autoProcessQueue: true,
                parallelUploads: 100,
                maxFilesize: @ViewBag.maxFilesize,//M
                paramName: "files",
                acceptedFiles: "@ViewBag.acceptedFiles",
                // Dropzone settings
                init: function () {
                    myDropzone = this;
                    this.on("sendingmultiple", function () {
                    });
                    this.on("successmultiple", function (files, response) {
                        //console.debug(files, response, "successmultiple");
                        //showUploadMessage(myDropzone, JSON.parse(file.xhr.response));
                    });
                    this.on("success", function (file) {
                        var data=JSON.parse(file.xhr.response);
                        if (!data.Success) {
                            mwc.notify.warn(data.Message);
                        }
                    });
                    this.on("complete", function (file) {
                        //if (file.xhr && file.xhr.response)
                        //    showUploadMessage(myDropzone, JSON.parse(file.xhr.response), file);
                    });
                    this.on("completemultiple", function (f) {
                        console.debug(f, "completemultiple");
                    });
                    this.on("errormultiple", function (files, response) {
                        var data=JSON.parse(response);
                        if (!data.Success) {
                            mwc.notify.warn(data.Message);
                        }
                    });
                    this.on("queuecomplete", function () {
                        console.debug(myDropzone,"queuecomplete");
                        //重新加载素材列表
                        parent.CurrentModel.Init();
                        setTimeout(function () {
                            mwc.window.closeSeft();
                        }, 800);
                    });
                }

            }

        });
    </script>
}
